<?php

class Quad_Data_Mask extends Quad_Data_Abstract {
	
	public $number;
	public $showNumDigits;
	
	public function __construct($number, $showNumDigits = 4) {
		$this->raw = $number;
		$this->number = trim($number);
		$this->showNumDigits = $showNumDigits;
	}
	
	public static function create($number, $showNumDigits = 4) {
		return new self($number, $showNumDigits);
	}
	
	public function format() {
		$totalNumDigits = strlen(preg_replace('/\W/', '', $this->number));
		$hideNumDigits = $totalNumDigits - $this->showNumDigits;
		$out = preg_replace('/\w/', 'X', $this->number, $hideNumDigits);
		return $out;
	}
	
}